package com.news.service.impl;

import com.github.pagehelper.PageHelper;

import com.news.mapper.AdminMapper;
import com.news.model.Admin;
import com.news.model.AdminExample;
import com.news.service.AdminService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class AdminServiceImpl implements AdminService {
    @Autowired
    private AdminMapper adminMapper;
    @Override
    public List<Admin> selectAdmin(String name) {
        AdminExample adminExample = new AdminExample();
        AdminExample.Criteria criteria = adminExample.createCriteria().andNameEqualTo(name);
        List<Admin> admins = adminMapper.selectByExample(adminExample);
        return admins;
    }

    @Override
    public void insert(Admin admin) {
        adminMapper.insert(admin);
    }

    @Override
    public void update(Admin admin) {
        //只更新不为空的字段
        adminMapper.updateByPrimaryKeySelective(admin);
    }

    @Override
    public void updateStatus(Admin admin) {
        adminMapper.updateByPrimaryKeySelective(admin);
    }

    @Override
    public List<Admin> queryAll(int pageNum, int pageSize) {
        PageHelper.startPage(pageNum,pageSize);
        AdminExample adminExample = new AdminExample();
        adminExample.setDistinct(false);
        List<Admin> admins = adminMapper.selectByExample(adminExample);
        return admins;
    }

    @Override
    public Admin queryOne(String id) {
        return adminMapper.selectByPrimaryKey(id);
    }
}
